﻿#include "coladdapprovaldialog.h"
#include "ui_coladdapprovaldialog.h"

#include <QDebug>

int COLaddApprovalDialog::D;

COLaddApprovalDialog::COLaddApprovalDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::COLaddApprovalDialog)
{
    ui->setupUi(this);
    ui->frame->resize(this->geometry().width(), ui->frame->height());
    ui->status->setText("添加信息状态：");
    ui->lenddate->setDate(QDate::currentDate());
    ui->returndate->setDate(QDate::currentDate());
    ui->unitdate->setDate(QDate::currentDate());
    ui->officedate->setDate(QDate::currentDate());
    ui->inquerydate->setDate(QDate::currentDate());
    connect(ui->cancelbtn,SIGNAL(clicked(bool)),this,SLOT(close()));
}


COLaddApprovalDialog::~COLaddApprovalDialog()
{
    delete ui;}


void COLaddApprovalDialog::receivedistinction(int distinction)
{D=distinction;}

void COLaddApprovalDialog::on_ackbtn_clicked()
{
    if(ui->lendway->text().isEmpty()||ui->unitlead->text().isEmpty()||ui->officelead->text().isEmpty()||ui->inquerylead->text().isEmpty()||ui->content->text().isEmpty()||ui->reason->text().isEmpty()){
        ui->status->setText("添加信息状态:请至少添入借阅和退还日期，借阅方式,查档事由，查档内容，各单位科室审批领导及日期");
   }
    else {
    QSqlQuery query;
    query.prepare("INSERT INTO Approval(ApprovalID,distinction,lendway,lenddate,returndate,recordman,reason,content,inquerylead,inquerydate,inqueryopinion,manageofficelead,manageofficedate,manageofficeopinion,manageunitlead,manageunitdate,manageunitopinion,others)"
                  "VALUES(:ApprovalID,:distinction,:lendway,:lenddate,:returndate,:recordman,:reason,:content,:inquerylead,:inquerydate,:inqueryopinion,:manageofficelead,:manageofficedate,:manageofficeopinion,:manageunitlead,:manageunitdate,:manageunitopinion,:others)");
    query.bindValue(":distinction",D);
    query.bindValue(":lendway",ui->lendway->text());
    query.bindValue(":lenddate",ui->lenddate->text());
    query.bindValue(":returndate",ui->returndate->text());
    query.bindValue(":recordman",ui->recordman->text());
    query.bindValue(":reason",ui->reason->text());
    query.bindValue(":content",ui->content->text());
    query.bindValue(":inquerylead",ui->inquerylead->text());
    query.bindValue(":inquerydate",ui->inquerydate->text());
    query.bindValue(":inqueryopinion",ui->inqueryopinion->text());
    query.bindValue(":manageofficelead",ui->officelead->text());
    query.bindValue(":manageofficedate",ui->officedate->text());
    query.bindValue(":manageofficeopinion",ui->officeopinion->text());
    query.bindValue(":manageunitlead",ui->unitlead->text());
    query.bindValue(":manageunitdate",ui->unitdate->text());
    query.bindValue(":manageunitopinion",ui->unitopinion->text());
    query.bindValue(":others",ui->others->text());
    bool ok=query.exec();
    if(ok)
    {ui->status->setText("添加信息状态:添加成功");
            this->close();}
    else
    {ui->status->setText("添加信息状态:添加失败");}
}
}
